package com.ruoyi.web.controller.societies;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.ClubActivities;
import com.ruoyi.system.domain.ClubCategories;
import com.ruoyi.system.domain.Clubs;
import com.ruoyi.system.service.IClubActivitiesService;
import com.ruoyi.system.service.IClubCategoriesService;
import com.ruoyi.system.service.IClubsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/public/societies")
public class PublicSocietiesController extends BaseController {

    @Autowired
    private IClubsService clubsService;

    @Autowired
    private IClubCategoriesService categoriesService;

    @Autowired
    private IClubActivitiesService clubActivitiesService;

    /**
     * 获取公开的社团列表（无需登录）
     */
    @GetMapping("/clubs")
    public TableDataInfo getPublicClubs(Clubs clubs) {
        // 只返回已审核通过的社团
        clubs.setStatus("已通过");
        startPage();
        List<Clubs> list = clubsService.selectClubsList(clubs);
        return getDataTable(list);
    }

    /**
     * 获取社团分类列表（无需登录）
     */
    @GetMapping("/categories")
    public AjaxResult getCategories() {
        List<ClubCategories> categories = categoriesService.selectClubCategoriesList(new ClubCategories());
        return success(categories);
    }

    /**
     * 获取社团详情（无需登录）
     */
    @GetMapping("/clubs/{clubId}")
    public AjaxResult getClubDetail(@PathVariable Long clubId) {
        Clubs club = clubsService.selectClubsByClubId(clubId);
        if (club != null && club.getStatus().equals("已通过") ) {
            return success(club);
        }
        return error("社团不存在或未通过审核");
    }

    /**
     * 获取公开的活动列表（无需登录）
     */
    @GetMapping("/activities")
    public TableDataInfo getPublicActivities(ClubActivities clubActivities) {
        startPage();
        List<ClubActivities> list = clubActivitiesService.selectPublicActivitiesList(clubActivities);
        return getDataTable(list);
    }
}
